import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadDemo9 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask=new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                String[] arrs=new String[]{"java","MySQL","Thread"};
                String result=arrs[new Random().nextInt(3)];
                System.out.println(Thread.currentThread().getName()+"--字符传:"+result);
                return result;
            }
        });
        //创建新线程
        Thread thread=new Thread(futureTask);
        //线程
        thread.start();
        String result=futureTask.get();
        System.out.println(Thread.currentThread().getName()+" 新线程的返回值"+result);

    }
}
